﻿@model GiftCardListModel
@using Telerik.Web.Mvc.UI
@{
    ViewBag.Title = T("Admin.GiftCards").Text;
}
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <i class="fa fa-gift"></i>
            @T("Admin.GiftCards")
        </div>
        <div class="options">
            <a href="@Url.Action("Create")" class="btn btn-primary">
                <i class="fa fa-plus"></i>
                <span>@T("Admin.Common.AddNew")</span>
            </a>
        </div>
    </div>

	<div class="row mt-3 grid-filter">
		<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
			@Html.SmartLabelFor(model => model.ActivatedId)
			@Html.DropDownListFor(model => model.ActivatedId, Model.ActivatedList, T("Admin.Common.All"))
		</div>
		<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
			@Html.SmartLabelFor(model => model.CouponCode)
			@Html.TextBoxFor(model => model.CouponCode, new { @class = "form-control" })
		</div>
		<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
			@Html.SmartLabel(string.Empty, string.Empty)
			<button type="submit" id="btnSearch" value="btnSearch" class="btn btn-secondary btn-block">
				<span>@T("Admin.Common.Search")</span>
			</button>
		</div>
	</div>
	
	<div>
		@(Html.Telerik().Grid<GiftCardModel>()
			.Name("giftcards-grid")
			.ClientEvents(events => events.OnDataBinding("onDataBinding"))
			.Columns(columns =>
			{
				columns.Bound(x => x.GiftCardCouponCode)
					.Template(x => Html.ActionLink(x.GiftCardCouponCode, "Edit", new { id = x.Id }))
					.ClientTemplate("<a href='Edit/<#= Id #>'><#= GiftCardCouponCode #></a>");
				columns.Bound(x => x.AmountStr);
				columns.Bound(x => x.RemainingAmountStr);
				columns.Bound(x => x.IsGiftCardActivated)
					.Template(item => @Html.SymbolForBool(item.IsGiftCardActivated))
					.ClientTemplate(@Html.SymbolForBool("IsGiftCardActivated"))
					.Centered()
					.Width(100);
				columns.Bound(x => x.CreatedOn);
				columns.Bound(x => x.Id)
					.Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "Edit", new { id = x.Id }, new { @class = "t-button" }))
					.ClientTemplate("<a href=\"Edit/<#= Id #>\" class=\"t-button\">" + T("Admin.Common.Edit").Text + "</a>")
					.Width(50)
					.Title(String.Empty)
					.HtmlAttributes(new { align = "right", @class = "omega" });
			})
			.Pageable(settings => settings.PageSize(Model.GridPageSize).Position(GridPagerPosition.Both))
			.DataBinding(dataBinding => dataBinding.Ajax().Select("GiftCardList", "GiftCard", Model))
			.PreserveGridState()
			.EnableCustomBinding(true))
	</div>
    
    <script type="text/javascript">

        $(document).ready(function () {

            $('#btnSearch').click(function () {
                var grid = $('#giftcards-grid').data('tGrid');
                grid.currentPage = 1; //new search. Set page size to 1
                grid.ajaxRequest();
                return false;
            });
        });

        function onDataBinding(e) {
            var searchModel = {
                ActivatedId: $('#@Html.FieldIdFor(model => model.ActivatedId)').val(),
                CouponCode: $('#@Html.FieldIdFor(model => model.CouponCode)').val()
            };
            e.data = searchModel;
        }

    </script>
    
}